<!DOCTYPE html>
<html lang="en">
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('章节列表')" />
</head>
<body class="gray_bg">
    <div class="container-div">
        <div class="btn-group-sm" id="toolbar">
            <a class="btn btn-success" onclick="$.operate.add()" >
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>
        <div class="row">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>

</body>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
   
    var prefix = ctx + "book/chapter";
    var book_id = [[${book_id}]];

    $(function(){

            var options = {
                modalName:"章节",
                url:prefix +"/list?book_id="+book_id,
                createUrl:prefix+"/add?book_id="+book_id,
                updateUrl:prefix+"/update/{id}",
                removeUrl:prefix+"/remove/{id}",
                uniqueId:"id",
                columns:[
                {
                        field:"chapter_id",
                        title:"chapter_id"
                    },
                    {
                        field:"title",
                        title:"标题"
                    },
                    {
                        field:"book_id",
                        title:"书id"
                    },
                    {
                        field:"price",
                        title:"价格(金币)"
                    },
                    {
                        field:"coin",
                        title:"金币"
                    },
                    {
		            title: '操作',
		            align: 'center',
		          formatter: function(value, row, index) {
                        var actions = [];
                        let id = row.book_id+"_"+row.chapter_id;
                        actions.push('<a class="btn btn-success btn-xs '  + '" href="javascript:void(0)" onclick="openEditContent(\'' + row.chapter_id + '\')"><i class="fa fa-edit"></i>编辑内容</a> ');
                        actions.push('<a class="btn btn-success btn-xs '  + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' +  '" href="javascript:void(0)" onclick="$.operate.remove(\'' + id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
		        }
                ]

            };
            $.table.init(options);

    });
    function openEditContent(chapter_id) {
    $.modal.open("编辑内容",prefix+"/updateContent?book_id="+book_id+"&chapter_id="+chapter_id);
    }

</script>
</html>